package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoDgConfConvert;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoDgConvert;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoSuspectedDgConvert;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoDgConfDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoDgDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoSuspectedDgDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoDgService;
import com.cmc.cloud.cmclink.doc.vo.special.dgextconfigvo.DgConfigVO;
import com.cmc.cloud.cmclink.doc.vo.special.dgextconfigvo.SpecialCargoDgConfBaseVO;
import com.cmc.cloud.cmclink.doc.vo.special.dgextconfigvo.SpecialCargoDgConfPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.special.dgextconfigvo.SpecialCargoDgConfRespVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargodgvo.*;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 特种货审批dg前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批dg")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/specialCargoDg")
public class SpecialCargoDgController {

    @Resource
    private SpecialCargoDgService specialCargoDgService;

    @Operation(summary = "创建特种货审批dg")
    @PostMapping("/createOrUpdate")
    public CommonResult<Long> createSpecialCargoDg(@Valid @RequestBody DgCreateOrUpdateReqVO createReqVO) {
        return CommonResult.success(specialCargoDgService.createSpecialCargoDg(createReqVO));
    }

    @Operation(summary = "更新特种货审批dg")
    @PostMapping("/update")
    public CommonResult<Void> updateSpecialCargoDg(@Valid @RequestBody SpecialCargoDgUpdateReqVO updateReqVO) {
        specialCargoDgService.updateSpecialCargoDg(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批dg")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoDg(@PathVariable("id") Long id) {
        specialCargoDgService.deleteSpecialCargoDg(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批dg")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<SpecialCargoDgRespVO> getSpecialCargoDg(@PathVariable("id") Long id) {
        SpecialCargoDgDO specialCargoDg = specialCargoDgService.getSpecialCargoDg(id);
        return CommonResult.success(SpecialCargoDgConvert.INSTANCE.convert(specialCargoDg));
    }

    @Operation(summary = "获得特种货审批dg列表")
    @GetMapping("/list")
    @Parameter(name = "applyId", description = "主信息ID", required = true)
    public CommonResult<List<SpecialCargoDgRespVO>> getSpecialCargoDgList(@RequestParam("applyId") Long applyId) {
        List<SpecialCargoDgDO> list = specialCargoDgService.getSpecialCargoDgList(applyId);
        return CommonResult.success(SpecialCargoDgConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得特种货审批dg分页")
    @PostMapping("/page")
    public CommonResult<PageResult<SpecialCargoDgRespVO>> getSpecialCargoDgPage(@RequestBody @Valid SpecialCargoDgPageReqVO pageVO) {
        PageResult<SpecialCargoDgDO> pageResult = specialCargoDgService.getSpecialCargoDgPage(pageVO);
        List<SpecialCargoDgRespVO> results = SpecialCargoDgConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @GetMapping("/getSegregation")
    @Operation(summary = "获取隔离组")
    @OperateLog(name = "获取隔离组", type = OperateTypeEnum.GET)
    public CommonResult<List<String>> getSegregation() {
        return CommonResult.success(specialCargoDgService.getSegregation());
    }
    @GetMapping("/getUnNo")
    @Operation(summary = "获取联合国编号UnNo")
    @OperateLog(name = "获取联合国编号UnNo", type = OperateTypeEnum.GET)
    public CommonResult<List<DgUnNoSimpleRespVO>> getUnNo() {
        return CommonResult.success(specialCargoDgService.getUnNo());
    }

    @GetMapping("/getImoClassAndPsn")
    @Operation(summary = "获取危险货物的分类体系和PSN")
    @OperateLog(name = "获取危险货物的分类体系和PSN", type = OperateTypeEnum.GET)
    public CommonResult<DgUnNoRespVO> getImoClassAndPsn(@RequestParam("unNo") String unNo) {
        return CommonResult.success(specialCargoDgService.getImoClassAndPsn(unNo));
    }

    @GetMapping("/checkIfDgExtByUnNo")
    @Operation(summary = "获取是否需要扩展字段")
    @OperateLog(name = "获取是否需要扩展字段", type = OperateTypeEnum.GET)
    public CommonResult<DgExtByUnNoVO> checkIfDgExtByUnNo(@RequestParam("unNo") String unNo) {
        return CommonResult.success(specialCargoDgService.checkIfDgExtByUnNo(unNo));
    }

    @PostMapping("/checkDgExtValue")
    @Operation(summary = "检查扩展字段值")
    @OperateLog(name = "检查扩展字段值", type = OperateTypeEnum.GET)
    public CommonResult<Void> checkDgExtValue(@RequestBody List<DgConfigVO> extArg) {
        specialCargoDgService.checkDgExtValue(extArg);
        return CommonResult.success();
    }

    @PostMapping("/getUnNoDgPage")
    @Operation(summary = "获取危险货物的分类体系和PSN-分页查询")
    @OperateLog(name = "获取危险货物的分类体系和PSN-分页查询", type = OperateTypeEnum.GET)
    public CommonResult<PageResult<DgUnNoSimpleRespVO>> getUnNoDgPage(@RequestBody UnNoDgPageReqVO pageVO) {
        return CommonResult.success(specialCargoDgService.getUnNoDgPage(pageVO));
    }

    @Operation(summary = "创建特种货DG关联配置")
    @PostMapping("/createDgCof")
    @PreAuthorize("@ss.hasPermission('doc:dangerousGoodsFieldConfig:add')")
    @OperateLog(name = "创建特种货DG关联配置", type = OperateTypeEnum.CREATE)
    public CommonResult<Void> createSpecialCargoDgConf(@Valid @RequestBody SpecialCargoDgConfBaseVO createReqVO) {
        specialCargoDgService.createSpecialCargoDgConf(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货DG关联配置")
    @PostMapping("/updateDgConf")
    @PreAuthorize("@ss.hasPermission('doc:dangerousGoodsFieldConfig:edit')")
    @OperateLog(name = "更新特种货DG关联配置", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateSpecialCargoDgConf(@Valid @RequestBody SpecialCargoDgConfBaseVO updateReqVO) {
        specialCargoDgService.updateSpecialCargoDgConf(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货DG关联配置")
    @PostMapping("/deleteDgConf/{id}")
    @PreAuthorize("@ss.hasPermission('doc:dangerousGoodsFieldConfig:delete')")
    @Parameter(name = "id", description = "编号", required = true)
    @OperateLog(name = "删除特种货DG关联配置", type = OperateTypeEnum.DELETE)
    public CommonResult<Void> deleteSpecialCargoDgConf(@PathVariable("id") Long id) {
        specialCargoDgService.deleteSpecialCargoDgConf(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货DG关联配置")
    @GetMapping("/getDgConf/{id}")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:dangerousGoodsFieldConfig:search')")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @OperateLog(name = "获得特种货DG关联配置", type = OperateTypeEnum.GET)
    public CommonResult<SpecialCargoDgConfRespVO> getSpecialCargoDgConf(@PathVariable("id") Long id) {
        SpecialCargoDgConfDO specialCargoDgConf = specialCargoDgService.getSpecialCargoDgConf(id);
        return CommonResult.success(SpecialCargoDgConfConvert.INSTANCE.convert(specialCargoDgConf));
    }

    @Operation(summary = "获得特种货DG关联配置分页")
    @PostMapping("/pageDgConf")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:dangerousGoodsFieldConfig:search')")
    @OperateLog(name = "获得特种货DG关联配置分页", type = OperateTypeEnum.GET)
    public CommonResult<PageResult<SpecialCargoDgConfRespVO>> getSpecialCargoDgConfPage(@RequestBody @Valid SpecialCargoDgConfPageReqVO pageVO) {
        PageResult<SpecialCargoDgConfRespVO> pageResult = specialCargoDgService.getSpecialCargoDgConfPage(pageVO);
        return CommonResult.success(pageResult);
    }

    @Operation(summary = "更新疑似危险品待处理清单")
    @PostMapping("/updateSuspectedDg")
    @OperateLog(name = "更新疑似危险品待处理清单", type = OperateTypeEnum.UPDATE)
    public CommonResult<Void> updateSpecialCargoSuspectedDg(@Valid @RequestBody SpecialCargoSuspectedDgBaseVO updateReqVO) {
        specialCargoDgService.updateSpecialCargoSuspectedDg(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除疑似危险品待处理清单")
    @PostMapping("/deleteSuspectedDg/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    @OperateLog(name = "删除疑似危险品待处理清单", type = OperateTypeEnum.DELETE)
    public CommonResult<Void> deleteSpecialCargoSuspectedDg(@PathVariable("id") Long id) {
        specialCargoDgService.deleteSpecialCargoSuspectedDg(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得疑似危险品待处理清单")
    @GetMapping("/getSuspectedDg/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @OperateLog(name = "获得疑似危险品待处理清单", type = OperateTypeEnum.GET)
    public CommonResult<SpecialCargoSuspectedDgBaseVO> getSpecialCargoSuspectedDg(@PathVariable("id") Long id) {
        SpecialCargoSuspectedDgDO specialCargoSuspectedDg = specialCargoDgService.getSpecialCargoSuspectedDg(id);
        return CommonResult.success(SpecialCargoSuspectedDgConvert.INSTANCE.convert(specialCargoSuspectedDg));
    }

    @Operation(summary = "获得疑似危险品待处理清单分页")
    @PostMapping("/pageSuspectedDg")
    @OperateLog(name = "获得疑似危险品待处理清单分页", type = OperateTypeEnum.GET)
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<SpecialCargoSuspectedDgBaseVO>> getSpecialCargoSuspectedDgPage(@RequestBody @Valid SpecialCargoSuspectedDgPageReqVO pageVO) {
        PageResult<SpecialCargoSuspectedDgBaseVO> pageResult = specialCargoDgService.getSpecialCargoSuspectedDgPage(pageVO);
        return CommonResult.success(pageResult);
    }
}
